package com.brspace.qualitycontrol.controller.admin;


import com.brspace.qualitycontrol.entity.Dept;
import com.brspace.qualitycontrol.mapper.DeptMapper;
import com.brspace.qualitycontrol.service.DeptService;
import com.brspace.qualitycontrol.utils.R;

import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author Hugo
 * @since 2021-04-18
 */
@RestController
@RequestMapping("/admin/dept")
public class DeptController {

    @Resource
    private DeptService deptService;

    @Resource
    private DeptMapper deptMapper;

    /**
     *部门注册
     *@author Hugo
     *@date 2021-04-18 14:52
     **/
    @PostMapping("save")
    public R save(Dept dept){
        deptService.saveInfor(dept);
        return R.ok();
    }
    
    /**
     *部门修改
     *@author Hugo
     *@date 2021-04-18 15:57
     **/
    @PostMapping("update")
    public R update(Dept dept){
        deptService.updateById(dept);
        return R.ok();
    }

    /**
     *部门删除
     *@author Hugo
     *@date 2021-04-18 16:00
     **/
    @PostMapping("delete/{id}")
    public R delete(@PathVariable String id){
        deptService.removeById(id);
        return R.ok();
    }

    /**
     *获取部门信息
     *@author Hugo
     *@date 2021-04-18 16:01
     **/
    @PostMapping("getInfo/{id}")
    public R getInfo(@PathVariable String id){
        return R.ok().data("list",deptService.getById(id));
    }


    /**
     *获取所有部门树形结构
     *@author Hugo
     *@date 2021-04-19 14:27
     **/
    @PostMapping("getTreeTotle")
    public R getTreeTotle(){
        return R.ok().data("list",deptService.getTreeList());
    }

}

